package com.huazi.www.user.wwwChaCtLuo.servlet;

import com.huazi.www.user.wwwChaCtLuo.entity.CtInfo;
import com.huazi.www.user.wwwChaCtLuo.service.ChaCtService;
import com.huazi.www.user.wwwChaCtLuo.service.impl.ChaCtServiceImpl;
import com.huazi.www.user.wwwChaCtLuo.util.Page;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author 罗义芳
 * @version 1.0
 * @date 2021/5/15 16:15
 **/
public class ChaCtServlet extends HttpServlet {
    /**
     * get请求和响应
     *
     * @param req  请求
     * @param resp 响应
     * @throws ServletException
     * @throws IOException
     */
    @Override
    public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    /**
     * post请求和响应
     *
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    @Override
    public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        String id = req.getParameter("id");//获取诊断id
        String name = req.getParameter("name");//获取患者名字
        String currentPage = req.getParameter("currentPage");//获取当前页面
        //设置默认值
        if (id == null || id.equals("")) {
            id = "-1";
        }
        if (name == null || name.equals("")) {
            name = "";
        }
        if (currentPage == null) {
            currentPage = "1";
        }
        Integer ids = Integer.parseInt(id);//将诊断id转换为int类型
        Integer currentPages = Integer.parseInt(currentPage);//将当前页转换为int类型
        ChaCtService chaCt = new ChaCtServiceImpl();
        Page<CtInfo> page = chaCt.findByPage(ids, name, currentPages);//获取到page对象
        req.setAttribute("id", id);
        req.setAttribute("name", name);
        req.setAttribute("page", page);
        req.getRequestDispatcher("depa/jsp/chaCt.jsp").forward(req, resp);
    }
}
